package com.ruoyi.project.hidden.hiddenSys.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.hidden.hiddenSys.domain.HiddenSys;
import com.ruoyi.project.hidden.hiddenSys.service.IHiddenSysService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 隐患系统Controller
 * 
 * @author ruoyi
 * @date 2021-01-21
 */
@Controller
@RequestMapping("/hidden/hiddenSys")
public class HiddenSysController extends BaseController
{
    private String prefix = "hidden/hiddenSys";

    @Autowired
    private IHiddenSysService hiddenSysService;

    @RequiresPermissions("hidden:hiddenSys:view")
    @GetMapping()
    public String hiddenSys()
    {
        return prefix + "/hiddenSys";
    }

    /**
     * 查询隐患系统列表
     */
    @RequiresPermissions("hidden:hiddenSys:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HiddenSys hiddenSys)
    {
        startPage();
        List<HiddenSys> list = hiddenSysService.selectHiddenSysList(hiddenSys);
        return getDataTable(list);
    }

    /**
     * 导出隐患系统列表
     */
    @RequiresPermissions("hidden:hiddenSys:export")
    @Log(title = "隐患系统", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HiddenSys hiddenSys)
    {
        List<HiddenSys> list = hiddenSysService.selectHiddenSysList(hiddenSys);
        ExcelUtil<HiddenSys> util = new ExcelUtil<HiddenSys>(HiddenSys.class);
        return util.exportExcel(list, "hiddenSys");
    }

    /**
     * 新增隐患系统
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存隐患系统
     */
    @RequiresPermissions("hidden:hiddenSys:add")
    @Log(title = "隐患系统", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HiddenSys hiddenSys)
    {
        return toAjax(hiddenSysService.insertHiddenSys(hiddenSys));
    }

    /**
     * 修改隐患系统
     */
    @GetMapping("/edit/{sysId}")
    public String edit(@PathVariable("sysId") Long sysId, ModelMap mmap)
    {
        HiddenSys hiddenSys = hiddenSysService.selectHiddenSysById(sysId);
        mmap.put("hiddenSys", hiddenSys);
        return prefix + "/edit";
    }

    /**
     * 修改保存隐患系统
     */
    @RequiresPermissions("hidden:hiddenSys:edit")
    @Log(title = "隐患系统", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HiddenSys hiddenSys)
    {
        return toAjax(hiddenSysService.updateHiddenSys(hiddenSys));
    }

    /**
     * 删除隐患系统
     */
    @RequiresPermissions("hidden:hiddenSys:remove")
    @Log(title = "隐患系统", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        int i = hiddenSysService.deleteHiddenSysByIds(ids);
        if (i==100){
            return error("此系统下面存在环节无法删除");
        }
        return toAjax(i);
    }



    @PostMapping( "/checkSysNameUnique")
    @ResponseBody
    public int checkLinkNameUnique(HiddenSys hiddenSys)
    {
        return hiddenSysService.checkSysNameUnique(hiddenSys);
    }
}
